'use strict';
const moment = require('moment');
module.exports = app => {
  const { INTEGER, STRING, DATE } = app.Sequelize;
  const Expense = app.model.define('expense', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    type: {
      type: STRING,
    },
    paytime: {
      type: DATE,
    },
    applytime: {
      type: DATE,
    },
    info: {
      type: STRING,
    },
    applicant: {
      type: INTEGER,
    },
    reviewer: {
      type: INTEGER,
    },
    r_info: {
      type: STRING,
    },
    state: {
      type: INTEGER,
    },
    money: {
      type: INTEGER,
    },
    created_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('created_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
    updated_at: {
      type: DATE,
      get() {
        return moment(this.getDataValue('updated_at')).format(
          'YYYY-MM-DD HH:mm:ss'
        );
      },
    },
  });

  Expense.associate = () => {
    Expense.belongsTo(app.model.Sys.User, {
      foreignKey: 'applicant',
    });
    Expense.belongsTo(app.model.Sys.User, {
      foreignKey: 'reviewer',
    });
  };
  return Expense;
};
